#include "C_ProgressBar.h"

using namespace gui;


C_ProgressBar::C_ProgressBar(C_Widget* parent) : C_Widget(parent)
{
	m_nowPer = 0;
	m_amtPer = 100;
	m_widthLine = 0.0f;

	m_lineColor.r = 0.0f; m_lineColor.g = 0.0f; m_lineColor.b = 1.0f; m_lineColor.a = 1.0f;
	m_backColor.r = 0.3f; m_backColor.g = 0.3f; m_backColor.b = 0.3f; m_backColor.a = 1.0f;

	m_label.setText(L"0%");
	this->setContainerType(CONTAINER_HORIZONTAL);
	this->setVerticalAlign(GRID_MIDDLE);
	this->setHorizontalAlign(GRID_CENTER);
	this->addWidget(&m_label);
}


C_ProgressBar::~C_ProgressBar()
{
}

void C_ProgressBar::renderWidget()
{
	glPushMatrix();
	glTranslatef(0.0f, margin().b, 0.0f);
	GLfloat vertex[] =
	{
		0.0f,					0.0f,
		0.0f,					size().y,
		m_widthLine*m_nowPer,	0.0f,
		m_widthLine*m_nowPer,	size().y
	};

	GLfloat vertexBack[] =
	{
		0.0f,		0.0f,
		0.0f,		size().y,
		size().x,	0.0f,
		size().x,	size().y
	};

	glEnableClientState(GL_VERTEX_ARRAY);
		////////////////////////////////////////////////////////////////
		/////////	DRAW BACK
		glColor4f(
			m_backColor.r,
			m_backColor.g,
			m_backColor.b,
			m_backColor.a
		);
		glVertexPointer(2, GL_FLOAT, 0, vertexBack);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

		////////////////////////////////////////////////////////////////
		/////////	DRAW LINE
		glColor4f(
			m_lineColor.r,
			m_lineColor.g,
			m_lineColor.b,
			m_lineColor.a
		);
		glVertexPointer(2, GL_FLOAT, 0, vertex);
		glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

	glDisableClientState(GL_VERTEX_ARRAY);
	glPopMatrix();
}
